<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
    
<body>
    <script>
        class Light{
            constructor(node) {
                this.parentNode = node;
                this.lightID = 1
                this.init();
                this.bind()
            }

            //初始化函数，页面初始渲染
            init() {
                let img = new Image();
                img.src = `./img/${this.lightID}.jpg`;
                this.parentNode.appendChild(img);
                this.img = img;
            }

            
            changeColor(){
                this.lightID == 3 && (this.lightID=0)
                this.lightID++
                this.img.src = `./img/${this.lightID}.jpg`
            }

            bind(){
                this.img.addEventListener('click',() => {
                    this.changeColor();
                })
            }
        }

        let light = new Light(document.body);

    </script>
</body>
</html>